﻿Public Class ucNods
	Inherits System.Web.UI.UserControl

	Public Event WriteToolTip(ByVal divtag As String)

	Dim Source As Entity.ChartItem
	Public WriteOnly Property DataSource As Entity.ChartItem
		Set(ByVal value As Entity.ChartItem)
			Source = value
		End Set
	End Property

	Dim mImageUrl As String
	Dim mWidth As WebControls.Unit
	Dim mHeight As WebControls.Unit

	Public WriteOnly Property ImageUrl As String
		Set(ByVal value As String)
			mImageUrl = value
		End Set
	End Property

	Public WriteOnly Property Width As WebControls.Unit
		Set(ByVal value As WebControls.Unit)
			mWidth = value
		End Set
	End Property

	Public WriteOnly Property Height As WebControls.Unit
		Set(ByVal value As WebControls.Unit)
			mHeight = value
		End Set
	End Property

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Me.hlNod.ImageUrl = mImageUrl
		Me.hlNod.Width = Me.mWidth
		Me.hlNod.Height = Me.mHeight

		If Source Is Nothing Then
			Exit Sub
		End If

		'reset to default
		Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/green/", "/gray/")
		Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/pink/", "/gray/")
		Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/yellow/", "/gray/")
		Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/blue/", "/gray/")
		Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/red/", "/gray/")
		Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/white/", "/gray/")
		Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/black/", "/gray/")

		Select Case Source.officer_status
			Case "NM"
				Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/gray/", "/green/")
			Case "EX"
				Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/gray/", "/pink/")
			Case "WN"
				Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/gray/", "/yellow/")
			Case "WT"
				Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/gray/", "/blue/")
			Case "EP"
				Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/gray/", "/red/")
			Case "N"
				Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/gray/", "/white/")
			Case "CE"
				Me.hlNod.ImageUrl = Me.hlNod.ImageUrl.Replace("/gray/", "/black/")
			Case Else
				'ไม่ต้องทำอะไร เพราะ Default = Gray (WC)
		End Select

		If Not Me.Source.officer_status.Equals("N") Then

			Dim strSpacilNod As String = String.Empty

			If Me.hlNod.ImageUrl.Contains("Untitled-1_02.png") Then
				strSpacilNod = "1"
			ElseIf Me.hlNod.ImageUrl.Contains("Untitled-1_06.png") Then
				strSpacilNod = "2"
			ElseIf Me.hlNod.ImageUrl.Contains("Untitled-1_08.png") Then
				strSpacilNod = "3"
			ElseIf Me.hlNod.ImageUrl.Contains("Untitled-1_12.png") Then
				strSpacilNod = "4"
			ElseIf Me.hlNod.ImageUrl.Contains("Untitled-1_14.png") Then
				strSpacilNod = "5"
			ElseIf Me.hlNod.ImageUrl.Contains("Untitled-1_16.png") Then
				strSpacilNod = "6"
			ElseIf Me.hlNod.ImageUrl.Contains("Untitled-1_18.png") Then
				strSpacilNod = "7"
			End If

			If Not String.IsNullOrEmpty(strSpacilNod) Then
				'Me.ltrPopup.Text = "<div id=""sticky"" class=""tooltip_" & strSpacilNod & "_name"">" & Me.Source.officer_firstname_tha & " " & Me.Source.officer_lastname_tha & "(" & Me.Source.offcier_app_tel & ")</div>"
				Me.ltrPopup.Text = "<div id=""sticky"" class=""tooltip_" & strSpacilNod & "_name"">" & Me.Source.officer_firstname_tha & " " & Me.Source.officer_lastname_tha & "</div>"
				Me.ltrPopup.Text &= "<div id=""sticky"" class=""tooltip_" & strSpacilNod & "_id"">" & Me.Source.officer_app_id & "(" & Me.Source.incomemyself & ")</div>"
				Me.ltrPopup.Text &= "<div id=""sticky"" class=""tooltip_" & strSpacilNod & "_lrv"">L:" & Me.Source.leftrv & "</div>"
				Me.ltrPopup.Text &= "<div id=""sticky"" class=""tooltip_" & strSpacilNod & "_rrv"">R:" & Me.Source.rightrv & "</div>"
				Me.hlNod.NavigateUrl = "~/OrgChart.aspx?key=" & Me.Source.officer_id
			Else
				Dim sbTag As New Text.StringBuilder
				sbTag.AppendLine("<div id=""sticky" & Me.ClientID & """ class=""atip"">")
				sbTag.AppendLine("<div>" & Me.Source.officer_app_id & "(" & Me.Source.incomemyself & ")</div>")
				'sbTag.AppendLine("<div>" & Me.Source.officer_firstname_tha & " " & Me.Source.officer_lastname_tha & "(" & Me.Source.offcier_app_tel & ")</div>")
				sbTag.AppendLine("<div>" & Me.Source.officer_firstname_tha & " " & Me.Source.officer_lastname_tha & "</div>")
				sbTag.AppendLine("<div>Real Value ด้านซ้าย : " & Me.Source.leftrv & "</div>")
				sbTag.AppendLine("<div>Real Value ด้านขวา : " & Me.Source.rightrv & "</div>")
				sbTag.AppendLine("</div>")
				Me.hlNod.Attributes.Add("data-tooltip", "sticky" & Me.ClientID)
				Me.hlNod.NavigateUrl = "~/OrgChart.aspx?key=" & Me.Source.officer_id
				RaiseEvent WriteToolTip(sbTag.ToString)
			End If
		End If
	End Sub

End Class